// 引入axios
let axios = require("axios");
// 引入less页面
require("./zjf-sport-course.less");
let dom = require("../../assets/js/zjf-dom.js");
document.addEventListener("DOMContentLoaded", function () {
	// 获取方法
	function $(v) {
		return document.querySelector(v);
	}
	//引用封装的底部导航栏
	dom.nav("sport");
	dom.nav2("course");

	axios.defaults.baseURL = "http://fitness.h5.itsource.cn:3701";
	let token = localStorage.getItem("token");
	axios.defaults.headers.common["Authorization"] = "Bearer " + token;
	axios.get("/api/train/courseList").then((v) => {
		let newcourse = v.data.data.shift();
		// 最新课程
		let dataarr = v.data.data;
		$("#newcourse a h4").textContent = newcourse.name;
		$("#newcourse a p").textContent = newcourse.desc.slice(0, 18) + "...";
		$("#newcourse a img").src = axios.defaults.baseURL + newcourse.imgurl;
		console.log(dataarr);
		dataarr.forEach((v) => {
			$("#nextcourse").innerHTML += `
			<a href="./zjf-sport-introduce.html?id=${v.courseId}">
					<img src="${axios.defaults.baseURL + v.imgurl}" alt="" />
					<h4>${v.name}</h4>
					<p>${v.desc}</p>
				</a>
			`;
		});
	});
});
